package topcoder;

public class BlackAndWhiteSolitaire {

	int minimumTurns(String S) {
		int N = S.length();
		int B[] = new int[N];
		int W[] = new int[N];
		
		B[0] = S.charAt(0) == 'B' ? 0 : 1;
		W[0] = S.charAt(0) == 'W' ? 0 : 1;
		
		for (int i = 1; i < N; i++) {
			B[i] = W[i-1];
			if(S.charAt(i) == 'W') B[i] += 1;
			W[i] = B[i-1];
			if(S.charAt(i) == 'B') W[i] += 1;
		}
		
		return Math.min(B[N-1], W[N-1]);
	}
	
	public static void main(String[] args) {
		BlackAndWhiteSolitaire r = new BlackAndWhiteSolitaire();
		System.out.println(r.minimumTurns("BBBW"));
	}
}
